// packageA/pages/jianzhi/jianzhi.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    appurl: app.apiurl,
    apiimg: app.apiimg,
    ggid:'',
    gglist:'',
    list:[],
    page_no:1,
    days: 0,
    hours: 0,
    minutes: 0,
    seconds: 0,
    endTime: 1722441600000, 
    // endTime: '2024/03/01 00:00:00',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.guanggao1()
    this.z_yonghu()
    this.z_jianzhi()
    this.z_jilu()
  },
  guanggao1(){
    let _this = this
    let params = {
      "token":wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/config/advertPage',
      method: 'POST',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        console.log(res.data.data)
         _this.guanggao2()
      }
    })
  },
  guanggao2(){
    let _this = this
    let params = {
      "token":wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/config/advert?page_id=10',
      method: 'GET',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
         _this.setData({
           gglist:res.data.data[0]
         })
      }
    })
  },
  z_kvlianjia(e){
    let _this = this
    let link_url = e.currentTarget.dataset.url
    let id = e.currentTarget.dataset.url
    if(link_url != undefined){
      wx.navigateTo({
        url: link_url,
      })
    }
  },
  z_yonghu(){
    let _this = this
    let params = {
      "token":wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/member/myInfo',
      method: 'POST',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
       if(res.data.code == '1001'){
         _this.setData({
           login:true,
           yonghu:res.data.data
         })
       }
      }
    })
  },
  z_jianzhi(){
    let _this = this
    let params = {
      "token":wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/member/memberJzInfoNew',
      method: 'POST',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
         _this.setData({
           jianzhi:res.data.data,
          //  endTime:res.data.data.djs_time
         })
        //  if(_this.data.yonghu.is_zb == '1'){
        //   _this.countDown()
        //  }
      }
    })
  },
  z_shauxin(){
    let _this = this
    _this.setData({
      jianzhi:''
    })
    _this.z_jianzhi()
  },
  z_jilu(){
    let _this = this
    let params = {
      "token":wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/member/memberJzRecord?page_no=1&page_num=500',
      method: 'GET',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        _this.setData({
          list: res.data.data.list
        })
        // if(_this.data.page_no == 1){
        //   _this.setData({
        //     list: res.data.data.list
        //   })
        // } else {
        //   let list = _this.data.list
        //   for(let i=0;i< res.data.data.list.length;i++){
        //     list.push(res.data.data.list[i])
        //   }
        //   _this.setData({
        //     list: list
        //   })
        // }
      }
    })
  },
  countDown: function () {
    const that = this;
    setInterval(function () {
      const nowTime = new Date().getTime();
      const endTime = that.data.endTime; // 替换日期格式并转换为时间戳
      let distance = endTime - nowTime;
      const days = Math.floor(distance / (1000 * 60 * 60 * 24));
      const hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
      const minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
      const seconds = Math.floor((distance % (1000 * 60)) / 1000);
 
      that.setData({
        days: that.formatTime(days),
        hours: that.formatTime(hours),
        minutes: that.formatTime(minutes),
        seconds: that.formatTime(seconds),
      });
    }, 1000);
  },
 
  formatTime: function (time) {
    return time < 10 ? '0' + time : time;
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
 //下滑刷新
 let _this = this
 let page_no  = _this.data.page_no
 page_no = page_no+1
 _this.setData({
   page_no:page_no
 })
 _this.z_jilu()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})